package com.ruoyi.system.service.vantservice.orderservice.impl;

import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderPicture;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderRetreat;
import com.ruoyi.system.mapper.vant.order.ApiOrderPictureMapper;
import com.ruoyi.system.mapper.vant.order.ApiOrderRetreatMapper;
import com.ruoyi.system.service.vantservice.orderservice.ApiOrderRetreatService;
import com.ruoyi.system.utils.IdentifiedGenerator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by 惠普 on 2020/12/26 18:55
 */
@Service("/apiOrderRetreatService")
public class ApiOrderRetreatServiceImpl implements ApiOrderRetreatService {
    @Resource
    private ApiOrderRetreatMapper apiOrderRetreatMapper;
    @Resource
    private ApiOrderPictureMapper apiOrderPictureMapper;

    /**
     * 退货信息添加,申请退货
     * @param orderRetreat
     * @return
     */
    @Override
    public int addOrderRetreat(OrderRetreat orderRetreat) {
        int row = 0;
        OrderRetreat orderRetreat1 = apiOrderRetreatMapper.selectOrderRetreatById(orderRetreat.getOrderId());
        if(orderRetreat1==null){
            int u = IdentifiedGenerator.Num();
            orderRetreat.setOrderRetreatPicture(u);
            row = apiOrderRetreatMapper.addOrderRetreat(orderRetreat);
            if(row == 1){
                IdentifiedGenerator.qu(orderRetreat.getFileList());
                for (Object s : orderRetreat.getFileList()) {
                    for (Map<String, Object> ss : orderRetreat.getUrlList()) {
                        OrderPicture orderPicture = new OrderPicture();
                        orderPicture.setOrderPictureUuid(u);
                        orderPicture.setOrderPictureUrl("http://51jhf.com/profile/xiazai/"+ss.get(s));
                        row = apiOrderPictureMapper.addOrderPicture(orderPicture);
                    }
                }
//                OrderPicture orderPicture = new OrderPicture();
//                orderPicture.setOrderPictureUuid(u);
//                if(orderRetreat.getImg0()!=null){
//                    orderPicture.setOrderPictureUrl(orderRetreat.getImg0());
//                    apiOrderPictureMapper.addOrderPicture(orderPicture);
//                }
//                if(orderRetreat.getImg1()!=null){
//                    orderPicture.setOrderPictureUrl(orderRetreat.getImg1());
//                    apiOrderPictureMapper.addOrderPicture(orderPicture);
//                }
//                if(orderRetreat.getImg2()!=null){
//                    orderPicture.setOrderPictureUrl(orderRetreat.getImg2());
//                    apiOrderPictureMapper.addOrderPicture(orderPicture);
//                }
//                if(orderRetreat.getImg3()!=null){
//                    orderPicture.setOrderPictureUrl(orderRetreat.getImg3());
//                    apiOrderPictureMapper.addOrderPicture(orderPicture);
//                }
            }
            return row;
        }else {
            row = 2;
            return row;
        }
    }

    /**
     * 根据id查询退货信息
     * @param orderId
     * @return
     */
    @Override
    public OrderRetreat selectOrderRetreatById(Integer orderId) {
        return apiOrderRetreatMapper.selectOrderRetreatById(orderId);
    }

    /**
     * 查询申请退货列表
     *
     * @param orderRetreat 申请退货
     * @return 申请退货
     */
    @Override
    public List<OrderRetreat> selectOrderRetreatList(OrderRetreat orderRetreat)
    {
        List<OrderRetreat> orderRetreats = apiOrderRetreatMapper.selectOrderRetreatList(orderRetreat);
        for (int i = 0; i < orderRetreats.size(); i++) {
            orderRetreats.get(i).setList(apiOrderPictureMapper.selectOrderPictureByUuid(orderRetreats.get(i).getOrderRetreatPicture()));
        }
        return orderRetreats;
    }


    /**
     * 修改申请退货
     *
     * @param orderRetreat 申请退货
     * @return 结果
     */
    @Override
    public int updateOrderRetreat(OrderRetreat orderRetreat)
    {
        return apiOrderRetreatMapper.updateOrderRetreat(orderRetreat);
    }

    @Override
    public OrderRetreat orderRetreatById(Integer orderRetreatId) {
        return apiOrderRetreatMapper.orderRetreatById(orderRetreatId);
    }

    @Override
    public OrderRetreat selectById(Integer orderId) {
        return apiOrderRetreatMapper.selectById(orderId);
    }

}
